<?php

declare(strict_types=1);

namespace DreamCat\Psr4Laravel\Bean;

use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Container\Container;
use Psr\Container\ContainerInterface;

/**
 * PSR容器
 * @author vijay
 */
class PsrContainer implements ContainerInterface
{
    public function __construct(private Container $container)
    {
    }

    /**
     * @inheritDoc
     */
    public function get(string $id)
    {
        return $this->container->make($id);
    }

    /**
     * @inheritDoc
     */
    public function has(string $id): bool
    {
        if ($this->container->bound($id)) {
            return true;
        }
        try {
            $this->container->make($id);
            return true;
        } catch (BindingResolutionException) {
            return false;
        }
    }
}

# end of file
